package spectra.ee.web.api.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import spectra.base.log.Logger;
import spectra.base.util.StringUtil;
import spectra.base.util.Util;
import spectra.ee.EEPublic;
import spectra.ee.commons.common.model.Attach;
import spectra.ee.commons.qna.model.QnaBoard;
import spectra.ee.commons.qna.model.QnaOption;
import spectra.ee.commons.qna.model.form.QnaForm;
import spectra.ee.commons.search.model.form.SearchKbForm;
import spectra.ee.web.WebConfig;
import spectra.ee.web.WebPublic;
import spectra.ee.web.api.ApiPublic;
import spectra.ee.web.common.model.Survey;
import spectra.ee.web.common.model.SurveyResponse;
import spectra.ee.web.common.model.SurveyResponseForm;
import spectra.ee.web.kb.model.Kb;
import spectra.ee.web.kb.model.TopKeyword;
import spectra.ee.web.node.model.Node;
import spectra.ee.web.qna.model.QnaBoardView;
import spectra.ee.web.qna.model.QnaWebForm;

/**
 * 호출하는 파라메터 타입을 담는 form 객체의 부모 객체.
 *  - spectra.ee.web.api.model 하위의 클래스들은 클라이언트에서 넘어오는 파라메터값을 담고 처리하는 form 객체입니다.
 *  - 모든 form 객체는 spectra.ee.web.api.model.ParameterForm 클래스를 상속받아 구현합니다.
 *  - 모든 form 객체는 Form 으로 끝나는 클래스명으로 작성합니다.
 *  - form 객체의 생성자는 request.getParameterMap 값을 파라메터로 받아서 파싱하여, 
 *  필수적으로 serviceName, command, formName 값을 셋팅하고, 
 *  나머지 파라메터 값들은 추후 서비스 모델 객체에 바인딩하기 위해 parameterMap 에 담습니다.
 * @author dhheo
 *
 */
public abstract class ParameterForm
{
	/** Logger객체. */
    private static Logger logger = Logger.getLoggerInstance(ParameterForm.class.getName());
    /** 사이트별 인증  키 */
    protected String authKey = null;
	/** The command. - 실행할 메소드 이름 ( namespace.method_name 형식 ) */
	protected String command = null;
	/** 서비스 이름 */
	protected String serviceName = null;
	/** 폼 이름 */
	protected String formName = null;
	/** 파라메터 맵 */
	protected Map parameterMap = null;
	/** 폼 객체 */
	protected Object form = null;
	
	public ParameterForm()
	{
		super();
	}
	
	protected ParameterForm(Map parameterMap) throws Exception
	{
		parsingAndSetting(parameterMap);
		setForm(bind());
	}
	
	public abstract void parsingAndSetting(Map parameterMap) throws Exception;
	
	/**
     * 서비스 단을 호출할때 넘겨줄 파라메터 객체를 생성한다.
     * 클라이언트에서 넘겨주는 form 파라메터의 값으로 맵핑한 모델 객체를 생성하고 넘어오는 파라메터를 각각에 맵핑한다.
     * 
     * @param ajaxForm 
     * @return
     */
    public final Object bind() throws Exception
    {
    	String formName = getFormName();
    	Object objForm = null;
    	if (StringUtil.isNotEmpty(formName))
    	{
	    	if (formName.equals(ApiPublic.FORM_KB))
	    	{
	    		String pageNo = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_PAGE_NO), "1");
	    		String rowsPerPage = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_ROWS_PER_PAGE), WebConfig.getEnvValue("FAQ_PAGE_ROW_COUNT"));
	    		
	    		int iRowsPerPage = Integer.parseInt(rowsPerPage);
	    		int iPageNo = Integer.parseInt(pageNo);
	    		int iStartNo = (iRowsPerPage * (iPageNo - 1)) + 1;
	    		int iEndNo = iPageNo * iRowsPerPage;
	    		
	    		Kb kb = new Kb();
	    		kb.setKbId((String)getParameterMap().get(ApiPublic.PARAM_KB_ID));
	    		kb.setDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	    		kb.setNodeId((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID));
	    		kb.setRowsPerPage(iRowsPerPage);
	    		kb.setStartNo(iStartNo);
	    		kb.setEndNo(iEndNo);
	    		kb.setOrderBy(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_ORDER_BY), WebConfig.getEnvValue("FAQ_PAGE_SORT_TYPE")));
	    		kb.setServiceType(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_SERVICE_TYPE), EEPublic.MODULE_TYPE_FAQ));
	    		kb.setLogId((String)getParameterMap().get(ApiPublic.PARAM_LOG_ID));
	    		kb.setTopnType(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_TOPN_TYPE), WebConfig.getEnvValue("FAQ_KB_TOPN_SYSTEM_TYPE")));
	    		objForm = kb;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_NODE))
	    	{
	    		Node node = new Node();
	    		node.setNodeId((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID));
	    		node.setParentId((String)getParameterMap().get(ApiPublic.PARAM_PARENT_ID));
	    		node.setServiceType((String)getParameterMap().get(ApiPublic.PARAM_SERVICE_TYPE));
	    		node.setDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	    		node.setAlias((String)getParameterMap().get(ApiPublic.PARAM_ALIAS));
	    		node.setDescription((String)getParameterMap().get(ApiPublic.PARAM_DESCRIPTION));
	    		node.setLevel(Integer.parseInt(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_LEVEL), "0")));
	    		objForm = node;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_TOPN_KEYWORD))
	    	{
	    		TopKeyword topKeyword = new TopKeyword();
	            topKeyword.setDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	            topKeyword.setServiceType((String)getParameterMap().get(ApiPublic.PARAM_SERVICE_TYPE));
	            topKeyword.setSystemType((String)getParameterMap().get(ApiPublic.PARAM_SYSTEM_TYPE));
	            topKeyword.setEndNo(Integer.parseInt(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_END_NO), "0")));
	            
	            objForm = topKeyword;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_ID))
	    	{
	    		objForm = (String)getParameterMap().get("id");
	    	}
	    	else if (formName.equals(ApiPublic.FORM_SEARCH))
	    	{
	    		String domainId = (String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID);
	    		String question = (String)getParameterMap().get(ApiPublic.PARAM_QUESTION);
	    		String searchRange = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_SEARCH_RANGE), "0");
	    		String searchReturnType = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_SEARCH_RETURN_TYPE), "1");
	    		String volume = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_VOLUME), "v01");
	    		String serviceType = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_SERVICE_TYPE), WebPublic.SERVICE_TYPE_FAQ);
	    		String isSearchLog = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_IS_SEARCH_LOG), "true");
	    		String isKeywordLog = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_IS_KEYWORD_LOG), "true");
	    		String nodeId = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID), "");
	    		String nodeIdPath = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID_PATH), "");
	    		String pageNo = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_PAGE_NO), "1");
	    		String isSearchHitCount = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_IS_SEARCH_HIT_COUNT), "true");
	    		String searchLogId = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_SEARCH_LOG_ID), Util.getGuid());
	    		String flag = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_FLAG), "2");
	    		String langFlag = (String)getParameterMap().get(ApiPublic.PARAM_LANG_FLAG);
	    		
	    		String rowsPerPage = StringUtil.defaultIfEmpty(WebConfig.getEnvValue("FAQ_PAGE_ROW_COUNT"), "10");
	    		String searchResultCount = StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_SEARCH_RESULT_COUNT), WebConfig.getEnvValue("FAQ_SEARCH_RESULT_COUNT"));
	    		
	    		SearchKbForm searchForm = new SearchKbForm();
	    		searchForm.setDomainId(domainId);
	    		searchForm.setQuestion(question);
	    		searchForm.setSearchRange(Byte.parseByte(searchRange));
	    		searchForm.setSearchReturnType(Byte.parseByte(searchReturnType));
	    		searchForm.setVolume(volume);
	    		searchForm.setServiceType(serviceType);
	    		searchForm.setIsSearchLog(Util.str2bl(isSearchLog));
	    		searchForm.setIsKeywordLog(Util.str2bl(isKeywordLog));
	    		searchForm.setNodeId(nodeId);
	    		searchForm.setNodeIdPath(nodeIdPath);
	    		searchForm.setPageNo(Integer.parseInt(pageNo));
	    		searchForm.setRowsPerPage(Integer.parseInt(rowsPerPage));
	    		searchForm.setSearchResultCount(Integer.parseInt(searchResultCount));
	    		searchForm.setIsSearchHitCount(Util.str2bl(isSearchHitCount));
	    		searchForm.setSearchLogId(searchLogId);
	    		searchForm.setFlag(Integer.parseInt(flag));
	    		searchForm.setLangFlag(langFlag);
	    		
	    		objForm = searchForm;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_SURVEY))
	    	{
	    		Survey survey = new Survey();
	    		survey.setDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	    		survey.setNodeId((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID));
	    		survey.setServiceType((String)getParameterMap().get(ApiPublic.PARAM_SERVICE_TYPE));
	    		survey.setSurveyType((String)getParameterMap().get(ApiPublic.PARAM_SURVEY_TYPE));
	    		survey.setQnaId((String)getParameterMap().get(ApiPublic.PARAM_QNA_ID));
	    		objForm = survey;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_SURVEY_RESPONSE))
	    	{
	    		SurveyResponse surveyResponse = new SurveyResponse();
	    		surveyResponse.setDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	    		surveyResponse.setSurveyId((String)getParameterMap().get(ApiPublic.PARAM_SURVEY_ID));
	    		surveyResponse.setSurveyItemId((String)getParameterMap().get(ApiPublic.PARAM_SURVEY_ITEM_ID));
	    		surveyResponse.setTargetId((String)getParameterMap().get(ApiPublic.PARAM_TARGET_ID));
	    		surveyResponse.setProcessSeq(Integer.parseInt(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_PROCESS_SEQ), "0")));
	    		surveyResponse.setResponseValue((String)getParameterMap().get(ApiPublic.PARAM_RESPONSE_VALUE));
	    		surveyResponse.setCodesetId((String)getParameterMap().get(ApiPublic.PARAM_CODESET_ID));
	    		surveyResponse.setResponderId((String)getParameterMap().get(ApiPublic.PARAM_RESPONDER_ID));
	    		surveyResponse.setResponderName((String)getParameterMap().get(ApiPublic.PARAM_RESPONDER_NAME));
	    		surveyResponse.setCreatedDate((String)getParameterMap().get(ApiPublic.PARAM_CREATED_DATE));
	    		surveyResponse.setServiceType(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_SERVICE_TYPE), WebPublic.SERVICE_TYPE_FAQ));
	    		objForm = surveyResponse;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_SURVEY_RESPONSE_LIST))
	    	{
	    		ArrayList dataList = ((ArrayList)getParameterMap().get(ApiPublic.PARAM_SURVEY_RESPONSE_LIST));
	    		objForm = dataList;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_SURVEY_RESPONSE_FORM_LIST))
	    	{
	    		ArrayList dataList = new ArrayList();

	    		String domainId = (String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID);
	    		String serviceType = (String)getParameterMap().get(ApiPublic.PARAM_SERVICE_TYPE);
	    		String surveyType = (String)getParameterMap().get(ApiPublic.PARAM_SURVEY_TYPE);
	    		String targetId = (String)getParameterMap().get(ApiPublic.PARAM_TARGET_ID);
	    		String responderId = (String)getParameterMap().get(ApiPublic.PARAM_RESPONDER_ID);
	    		String responderName = (String)getParameterMap().get(ApiPublic.PARAM_RESPONDER_NAME);
	    		String strSurveyResponseList = (String)getParameterMap().get(ApiPublic.PARAM_SURVEY_RESPONSE_LIST);
	    		int processSeq = Integer.parseInt(StringUtil.defaultIfEmpty(StringUtil.defaultString((String)getParameterMap().get(ApiPublic.PARAM_PROCESS_SEQ)), "0"));
	    		
	    		/* JSON 객체 형태의 surveyResponseList를 파싱한다. */
	    		if (!StringUtil.isEmpty(strSurveyResponseList))
        		{
	    			JSONObject jo = JSONObject.fromObject(strSurveyResponseList);
		          	JSONArray ja = jo.getJSONArray("surveyResponseList");
		          	
		          	SurveyResponseForm surveyResponse = null;
		          	for (Iterator i = ja.iterator(); i.hasNext();)
		          	{          
		              	JSONObject ob = (JSONObject) i.next();
		              	
		              	if (!ob.has(ApiPublic.PARAM_RESPONSE_VALUE))
		                {            	
		                	continue;
		                }
		              	
		              	surveyResponse = new SurveyResponseForm();
		              	surveyResponse.setSurveyId(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_SURVEY_ID)));
			    		surveyResponse.setSurveyItemId(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_SURVEY_ITEM_ID)));
			    		surveyResponse.setInputType(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_INPUT_TYPE)));
			    		surveyResponse.setAnswerType(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_ANSWER_TYPE)));
			    		surveyResponse.setCodesetId(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_CODESET_ID)));
			    		surveyResponse.setCodesetType(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_CODESET_TYPE)));
			    		surveyResponse.setMappingId(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_MAPPING_ID)));
			    		surveyResponse.setMappingType(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_MAPPING_TYPE)));
			    		surveyResponse.setTargetTable(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_TARGET_TABLE)));
			    		surveyResponse.setTargetField(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_TARGET_FIELD)));
			    		
			    		surveyResponse.setResponseValue(StringUtil.defaultString(ob.getString(ApiPublic.PARAM_RESPONSE_VALUE)));
			    		
			    		surveyResponse.setDomainId(domainId);
			    		surveyResponse.setServiceType(serviceType);
			    		surveyResponse.setSurveyType(surveyType);
			    		surveyResponse.setProcessSeq(processSeq);
			    		surveyResponse.setTargetId(targetId);
			    		surveyResponse.setResponderId(responderId);
			    		surveyResponse.setResponderName(responderName);
			    		
			    		dataList.add(surveyResponse);
		          	}
        		}

	    		objForm = dataList;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_QNA_BOARD))
	    	{
	    		QnaBoardView qnaBoardView = new QnaBoardView();
	    		qnaBoardView.setQnaId((String)getParameterMap().get(ApiPublic.PARAM_QNA_ID));
	    		qnaBoardView.setQnaDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	    		qnaBoardView.setCustomerId((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_ID));
	    		qnaBoardView.setChannelId((String)getParameterMap().get(ApiPublic.PARAM_CHANNEL_ID));
	    		qnaBoardView.setOrderBy((String)getParameterMap().get(ApiPublic.PARAM_ORDER_BY));
	    		qnaBoardView.setRowsPerPage(Util.str2i((String)getParameterMap().get(ApiPublic.PARAM_ROWS_PER_PAGE), 0));
	    		qnaBoardView.setPageNo(Util.str2i((String)getParameterMap().get(ApiPublic.PARAM_PAGE_NO), 0));
	    		qnaBoardView.setEndNo(qnaBoardView.getPageNo() * qnaBoardView.getRowsPerPage());
	    		qnaBoardView.setStartNo(qnaBoardView.getRowsPerPage() * (qnaBoardView.getPageNo() - 1) + 1);
	    		qnaBoardView.setSearchNodeId((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID));
	    		qnaBoardView.setSearchKeyword((String)getParameterMap().get(ApiPublic.PARAM_KEYWORD));
	    		qnaBoardView.setSearchCondition((String)getParameterMap().get(ApiPublic.PARAM_CONDITION));
	    		qnaBoardView.setWebviewFlag((String)getParameterMap().get(ApiPublic.PARAM_WEBVIEW_FLAG));
	    		objForm = qnaBoardView;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_QNA))
	    	{
	    		QnaForm qnaForm = new QnaForm();
	            qnaForm.setQnaId((String)getParameterMap().get(ApiPublic.PARAM_QNA_ID));
	            qnaForm.setDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	            qnaForm.setNodeId((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID));
	            qnaForm.setCustomerId((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_ID));
	            qnaForm.setCustomerEmail((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_EMAIL));
	            qnaForm.setCustomerName((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_NAME));
	            qnaForm.setCustomerTel((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_TEL));
	            qnaForm.setCustomerNo((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_NO));
	            
	            qnaForm.setQuestionChannelId((String)getParameterMap().get(ApiPublic.PARAM_CHANNEL_ID));
	            qnaForm.setQuestionTitle((String)getParameterMap().get(ApiPublic.PARAM_QUESTION_TITLE));
	            qnaForm.setQuestionContents((String)getParameterMap().get(ApiPublic.PARAM_QUESTION_CONTENTS));
	            
	            //qna_board 용 파라메터
	            //qnaForm.getQnaBoard() 에서 webviewFlag 를 qnaForm 값으로 qnaBoard 객체에 다시 담기 때문에...
	            qnaForm.setWebviewFlag((String)getParameterMap().get(ApiPublic.PARAM_WEBVIEW_FLAG));
	            
	            QnaBoard qnaBoard = qnaForm.getQnaBoard();
	            qnaBoard.setPublicFlag((String)getParameterMap().get(ApiPublic.PARAM_PUBLIC_FLAG));
	            qnaBoard.setPassword((String)getParameterMap().get(ApiPublic.PARAM_PASSWORD));
	            qnaForm.setQnaBoard(qnaBoard);
	            
	            //첨부파일이 있으면 폼에 담는다.
	            if (!StringUtil.isEmpty((String)getParameterMap().get(ApiPublic.FIELD_FILENAME)))
        		{
	            	//첨부파일은 현재 1개만 지원한다.
	            	//String kbId, int processSeq, int attachSeq, String attachName, String attachPath, int attachSize, String attachExt, String createdBy, String createdDate)
		            Attach attach = new Attach("", 0, 0,  
		            		(String)getParameterMap().get(ApiPublic.FIELD_FILENAME),
		            		(String)getParameterMap().get(ApiPublic.FIELD_FILEPATH),
		            		((Long)getParameterMap().get(ApiPublic.FIELD_FILESIZE)).intValue(),
		            		(String)getParameterMap().get(ApiPublic.FIELD_FILEEXT), "", "");
		            List questionAttachList = new ArrayList();
		            questionAttachList.add(attach);
		            qnaForm.setQuestionAttachCount(1);
		            qnaForm.setQuestionAttachList(questionAttachList);
        		}
	            
	            objForm = qnaForm;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_QNA_WEB))
	    	{
	    		QnaWebForm qnaWebForm = new QnaWebForm();
	    		
	    		qnaWebForm.setQnaId((String)getParameterMap().get(ApiPublic.PARAM_QNA_ID));
	    		qnaWebForm.setDomainId((String)getParameterMap().get(ApiPublic.PARAM_DOMAIN_ID));
	    		qnaWebForm.setNodeId((String)getParameterMap().get(ApiPublic.PARAM_NODE_ID));
	    		
	    		qnaWebForm.setCustomerId((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_ID));
	            qnaWebForm.setCustomerEmail((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_EMAIL));
	            qnaWebForm.setCustomerName((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_NAME));
	            qnaWebForm.setCustomerTel((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_TEL));
	            qnaWebForm.setCustomerNo((String)getParameterMap().get(ApiPublic.PARAM_CUSTOMER_NO));
	            
	            qnaWebForm.setQuestionChannelId((String)getParameterMap().get(ApiPublic.PARAM_CHANNEL_ID));
	            qnaWebForm.setQuestionTitle((String)getParameterMap().get(ApiPublic.PARAM_QUESTION_TITLE));
	            qnaWebForm.setQuestionContents((String)getParameterMap().get(ApiPublic.PARAM_QUESTION_CONTENTS));
	            
	            // qna_board 용 파라메터
	            // qnaWebForm.getQnaBoard() 에서 webviewFlag 를 qnaWebForm 값으로 qnaBoard 객체에 다시 담기 때문에...
	            qnaWebForm.setWebviewFlag((String)getParameterMap().get(ApiPublic.PARAM_WEBVIEW_FLAG));
	            
	            QnaBoard qnaBoard = qnaWebForm.getQnaBoard();
	            qnaBoard.setPublicFlag((String)getParameterMap().get(ApiPublic.PARAM_PUBLIC_FLAG));
	            qnaBoard.setPassword((String)getParameterMap().get(ApiPublic.PARAM_PASSWORD));
	            qnaWebForm.setQnaBoard(qnaBoard);
	            
	            // 첨부파일
	            int iAttachCount = Integer.parseInt(StringUtil.defaultIfEmpty((String)getParameterMap().get(ApiPublic.PARAM_ATTACH_COUNT), "0"));
	            if(iAttachCount > 0)
	            {
	            	String strAttachList = (String)getParameterMap().get(ApiPublic.PARAM_ATTACH);
	                StringTokenizer stAttach = new StringTokenizer(strAttachList, "\\");
	                String[] arrAttach = new String[iAttachCount];
	                ArrayList attach = new ArrayList();

	                // 첨부파일이 있다면 개수만큼 t_attach 변수 셋팅하여 ArrayList에 담음.
	                for (int i = 0; i < iAttachCount; i++)
	                {
	                    if (stAttach.hasMoreElements())
	                    {
	                        arrAttach[i] = (String) stAttach.nextElement();
	                        StringTokenizer stAttachElement = new StringTokenizer(arrAttach[i], "|");

	                        if (stAttachElement.hasMoreElements())
	                        {
	                            try
	                            {
	                            	// [0]path, [1]name, [2]size
	                            	String strAttachPath = (String)stAttachElement.nextElement();
	                                strAttachPath = "/" + strAttachPath.substring(strAttachPath.indexOf("qna/inbound"), strAttachPath.length());
	                                
	                                String attachName = (String)stAttachElement.nextElement();
	                                String attachSize = (String)stAttachElement.nextElement();
	                                
	                                Attach attachBean = new Attach();
	                                attachBean.setProcessSeq(0);
	                                attachBean.setAttachSeq(i);
	                                attachBean.setAttachPath(strAttachPath);
	                                attachBean.setAttachName(attachName);
	                                attachBean.setAttachSize(Long.parseLong(attachSize));
	                                attachBean.setAttachExt(attachName.substring(attachName.lastIndexOf(".")+1, attachName.length()));
	                                
	                                attach.add(attachBean);
	                            }
	                            catch(Exception e){}
	                        }
	                    }
	                }
	                
	                qnaWebForm.setQuestionAttachCount(iAttachCount);
	                qnaWebForm.setQuestionAttachList(attach);
	            }
	            
	            objForm = qnaWebForm;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_QNA_OPTION))
	    	{
	    		QnaOption qnaOption = new QnaOption();
	    		qnaOption.setQnaId((String)getParameterMap().get(ApiPublic.PARAM_QNA_ID));
	    		qnaOption.setOption01((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"01"));
	            qnaOption.setOption02((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"02"));
	            qnaOption.setOption03((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"03"));
	            qnaOption.setOption04((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"04"));
	            qnaOption.setOption05((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"05"));
	            qnaOption.setOption06((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"06"));
	            qnaOption.setOption07((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"07"));
	            qnaOption.setOption08((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"08"));
	            qnaOption.setOption09((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"09"));
	            qnaOption.setOption10((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"10"));
	            qnaOption.setOption11((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"11"));
	            qnaOption.setOption12((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"12"));
	            qnaOption.setOption13((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"13"));
	            qnaOption.setOption14((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"14"));
	            qnaOption.setOption15((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"15"));
	            qnaOption.setOption16((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"16"));
	            qnaOption.setOption17((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"17"));
	            qnaOption.setOption18((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"18"));
	            qnaOption.setOption19((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"19"));
	            qnaOption.setOption20((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"20"));
	            qnaOption.setOption21((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"21"));
	            qnaOption.setOption22((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"22"));
	            qnaOption.setOption23((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"23"));
	            qnaOption.setOption24((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"24"));
	            qnaOption.setOption25((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"25"));
	            qnaOption.setOption26((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"26"));
	            qnaOption.setOption27((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"27"));
	            qnaOption.setOption28((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"28"));
	            qnaOption.setOption29((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"29"));
	    		qnaOption.setOption30((String)getParameterMap().get(ApiPublic.PARAM_QNA_OPTION+"30"));
	    		
	    		objForm = qnaOption;
	    	}
	    	else if (formName.equals(ApiPublic.FORM_ATTACH))
	    	{
	    		String kbId = (String)getParameterMap().get(ApiPublic.PARAM_KB_ID);
	    		
	    		Attach attach = new Attach();
	    		attach.setKbId(kbId);
	    		
	    		objForm = attach;
	    	}
	    	else
	    	{
	    		logger.error("form parameter invalid : form parameter '" + formName + "' but can't find model object");
	    		throw new Exception("form parameter invalid : form parameter '" + formName + "' but can't find model object");
	    	}
    	}
    	else
    	{
    		objForm = null;
    	}
    	return objForm;
    }
    
    public String getAuthKey()
    {
    	return authKey;
    }
    
    public void setAuthKey(String authKey)
    {
    	this.authKey = authKey;
    }

	public String getCommand()
	{
		return command;
	}

	public void setCommand(String command)
	{
		this.command = command;
	}

	public String getServiceName()
	{
		return serviceName;
	}

	public void setServiceName(String serviceName)
	{
		this.serviceName = serviceName;
	}

	public String getFormName()
	{
		return formName;
	}

	public void setFormName(String formName)
	{
		this.formName = formName;
	}
	
	public Object getForm()
	{
		return this.form;
	}
	
	public void setForm(Object form)
	{
		this.form = form;
	}
	
	public Map getParameterMap()
	{
		return this.parameterMap;
	}
	
	public void setParameterMap(Map parameterMap)
	{
		this.parameterMap = parameterMap;
	}
	

}